import time

from appium import webdriver
class Base():
    def __init__(self):
        cap={
            "platformName": "Android",
            "appium:deviceName": "emulator-5554",
            "appium:automationName": "uiautomator2",
            "appium:appPackage": "com.kongfz.app",
            "appium:appActivity": ".home.mvvm.homepage.HomeActivity",
            "appium:noReset": True
        }
        self.driver=webdriver.Remote('http://127.0.0.1:4723/wd/hub',cap)
        self.driver.implicitly_wait(20)#隐式等待
    def find_ele(self,loc):#找元素
        ele=self.driver.find_element(*loc)
        return ele
    def find_ele_wait(self,loc):#显式等待
        ele=self.driver.find_element(loc)
        return ele
    def jietu(self,a):
        t=time.strftime("%Y%m%d%H%M%S",time.localtime())#时间戳
        self.driver.save_screenshot(t+a)#截图
    def qingqiao(self,a,b):#轻敲
        self.driver.tap([(a,b)],300)
    def huadong(self,a,b,c,d):#滑动
        self.driver.swipe(a,b,c,d,300)
    def tuichu(self):#退出
        self.driver.quit()
    def anjian(self,a):#按键
        self.driver.press_keycode(a)
